package com.quantice.mainActivity;


import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.EditText;

public class DatePickerFragment extends DialogFragment implements
		DatePickerDialog.OnDateSetListener {
	EditText textoAdd;

	public DatePickerFragment(EditText v) {
		textoAdd = v;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// Use the current date as the default date in the picker
		final Calendar c = Calendar.getInstance();
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH);
		int day = c.get(Calendar.DAY_OF_MONTH);
		String aceptar = getResources().getString(R.string.aceptar);
		String cancelar = getResources().getString(R.string.cancelar);

		DatePickerDialog nuevoDPD = new DatePickerDialog(getActivity(), this,
				year, month, day);
		nuevoDPD.setButton(DatePickerDialog.BUTTON_POSITIVE, aceptar, nuevoDPD);
		nuevoDPD.setButton(DatePickerDialog.BUTTON_NEGATIVE, cancelar, nuevoDPD);
		nuevoDPD.setTitle(R.string.setdate);

		// Create a new instance of DatePickerDialog and return it
		return nuevoDPD;
	}

	public void onDateSet(DatePicker view, int year, int month, int day) {
		// Do something with the date chosen by the user
		view.updateDate(year, ++month, day);
		textoAdd.setText(day + "/" + month + "/" + year);
	}
}